$\Delta$CoVaR Estimation

Contributor: Haochen Jiang
May 6, 2022

In [1]:
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
In [2]:
import math
import scipy
import nlopt
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import datetime as dt

import statsmodels.api as sma
from statsmodels.regression.quantile_regression import QuantReg as qr
from datetime import datetime

Please make sure to input your Data path in your computer in the following format

In [3]:
path = "D:\\Data\\"

Please make sure to research time period in your computer in the following format:
By the way, however, S&P 500 real estate sector index data before 2002/2/11 and after 2021/12/31 is not available!

In [4]:
start = dt.datetime(year=2002, month=12, day=31)
end = dt.datetime(year=2021, month=12, day=31)

Linux Debug Environment

In [5]:
#! pip install nlopt
#! pip install yfinance
#! pip install pandas_datareader
In [6]:
#path = "/home/jovyan/demo/Data/"

VaR Calculation¶

In [33]:
window_size = 52 * 3

Nonparametric method - Historical Data¶

In [34]:
def historical_var(stock_name, q, window_size = window_size, stocks_losses_series = stocks_losses_W_pct):
    return stocks_losses_series[stock_name].dropna().rolling(
        window = window_size, min_periods = int(0.8 * window_size)
    ).apply(lambda x: np.quantile(x, q)).dropna().rename(stock_name + "_VaR_" + str(q))

Semiparametric method - Formula¶

In [35]:
def formula_var(stock_name, q, window_size = window_size, stocks_losses_series = stocks_losses_W_pct):
    rolling = stocks_losses_series[stock_name].dropna().rolling(window = window_size, min_periods = int(0.8 * window_size))
    mean_series = rolling.mean()
    std_series = rolling.std()
    return (mean_series + scipy.stats.norm.ppf(q) * std_series).dropna().rename(stock_name + "_VaR_" + str(q))

Parametric method - MLE¶

In [36]:
def Trs(df):
    return np.array(df.T)[0]

def regularize(series_i, market_losses_series, state_variables_series):
    series_i = series_i.dropna().copy()
    mkt = market_losses_series.copy()
    svs_lagged = state_variables_series.copy().shift(1).dropna()
    common = svs_lagged.index.intersection(series_i.index)
    mkt = mkt.loc[common,:]
    series_i = series_i.loc[common]
    svs_lagged = svs_lagged.loc[common,:]
    return series_i, mkt, svs_lagged
In [37]:
def log_likelihood_norm(params, series_i, mkt, svs_lagged):
    pi = math.pi
    n = series_i.shape[0]
    mu, sigma, p0, p1_0, p1_1, p1_2, p1_3, p1_4, p1_5, p1_6, p2, p3, p4_0, p4_1, p4_2, p4_3, p4_4, p4_5, p4_6, p5 = params
    p1_v = np.array([p1_0, p1_1, p1_2, p1_3, p1_4, p1_5, p1_6])
    p4_v = np.array([p4_0, p4_1, p4_2, p4_3, p4_4, p4_5, p4_6])

    part1 = (-n) * np.log(sigma)
    part2 = (-n / 2) * np.log(2 * pi)
    part3 = (-1.0 / 2 / np.power(sigma, 2)) * (sum(np.power(
            mu - (Trs(mkt) - p0 - p1_v.dot(svs_lagged.T) - p2 * Trs(series_i))
                / (p3 + p4_v.dot(svs_lagged.T) + p5 * Trs(series_i)), 2)))
    ll = part1 + part2 + part3
    return ll
In [38]:
def fit_mle_norm(series_i, mkt, svs_lagged, initial_guess = None):

    def mle_objective(temp, grad):
        assert len(grad) == 0
        assert len(temp) == 20
        return -log_likelihood_norm(temp, series_i, mkt, svs_lagged)

    lb = [-10, 0] + [-10] + [-1, -5, -0.3, -6, -4, -3, -10] + [-5, -10] + [-1, -5, -0.3, -6, -4, -3, -10] + [-5]
    ub = [10, 10] + [10] + [1, 5, 0.3, 6, 4, 3, 10] + [5, 10] + [1, 5, 0.3, 6, 4, 3, 10] + [5]
    opt = nlopt.opt(nlopt.LN_COBYLA, 20)
    opt.set_lower_bounds(lb)
    opt.set_upper_bounds(ub)
    opt.set_min_objective(mle_objective)
    opt.set_xtol_rel(1e-2)
    opt.set_ftol_abs(1e-3)

    if initial_guess is None:
        x0 = [0.2] * 20
    else:
        x0 = initial_guess
    x = opt.optimize(x0)

    assert opt.last_optimize_result() in [nlopt.SUCCESS, nlopt.FTOL_REACHED, nlopt.XTOL_REACHED]
    # print(x)
    return x
In [39]:
def MLE_var_result(params, stock_name, q, series_i, mkt, svs_lagged):
    mu, sigma, p0, p1_0, p1_1, p1_2, p1_3, p1_4, p1_5, p1_6, p2, p3, p4_0, p4_1, p4_2, p4_3, p4_4, p4_5, p4_6, p5 = params
    p1_v = np.array([p1_0, p1_1, p1_2, p1_3, p1_4, p1_5, p1_6])
    p4_v = np.array([p4_0, p4_1, p4_2, p4_3, p4_4, p4_5, p4_6])

    loc_series = p0 + p1_v.dot(svs_lagged.T) + p2 * Trs(series_i)
    scale_series = p3 + p4_v.dot(svs_lagged.T) + p5 * Trs(series_i)
    err_series = (Trs(mkt) - loc_series) / scale_series
    var_series = []
    for i in range(err_series.shape[0]):
        var_series.append(scipy.stats.norm(loc_series[i] + mu * scale_series[i], scale_series[i] * sigma).ppf(q))
    loc_series = pd.Series(loc_series, index = mkt.index, name = "loc")
    scale_series = pd.Series(scale_series, index = mkt.index, name = "scale")
    var_series = pd.Series(var_series, index = mkt.index, name = stock_name + "_VaR_" + str(q))
    error_series = pd.Series(err_series, index = mkt.index, name = "error_term")
    return var_series, (mu, sigma), pd.concat([var_series, error_series, loc_series, scale_series], axis = 1)
In [40]:
def MLE_var(stock_name, q,
            market_losses_series = market_losses_W_pct,
            stocks_losses_series = stocks_losses_W_pct,
            state_variables_series = stateVariables_W):

    stk, mkt, svs_lagged = regularize(stocks_losses_series[stock_name], market_losses_series, state_variables_series)
    params = fit_mle_norm(stk, mkt, svs_lagged)
    return MLE_var_result(params, stock_name, q, stk, mkt, svs_lagged)

Parametric method - Quantile Regression¶

In [41]:
def qr_var(stock_name, q, modified = True,
           state_variables_series = stateVariables_W,
           stocks_losses_series = stocks_losses_W_pct):

    stk = stocks_losses_series[stock_name].dropna().copy()
    svs_lagged = state_variables_series.copy().shift(1).dropna()
    if modified:
        stk_lagged = stk.shift(1).dropna()
        common = stk_lagged.index.intersection(svs_lagged.index)
        stk = stk.loc[common]
        reg = svs_lagged.loc[common,:]
        reg["stock_lagged"] = stk_lagged.loc[common]
    else:
        common = stk.index.intersection(svs_lagged.index)
        stk = stk.loc[common]
        reg = svs_lagged.loc[common,:]

    qr_model = qr(stk, sma.add_constant(reg)).fit(q)
    qr_var_values = qr_model.fittedvalues.rename(stock_name + "_VaR_" + str(q))
    return qr_var_values, qr_model

Summary Function¶

In [42]:
def var(stock_name, q, qr_var_method, qr_var_modified = True):
    if qr_var_method != qr_var and qr_var_modified == False:
        raise Exception("Input Error! Only Quantile Regression VaR model can be modified!")
    if qr_var_method == qr_var:
        if qr_var_modified:
            stk_var = qr_var_method(stock_name, q)[0]
        else:
            stk_var = qr_var_method(stock_name, q, modified = False)[0]
    elif qr_var_method == MLE_var:
        stk_var = qr_var_method(stock_name, q)[0]
    else:
        stk_var = qr_var_method(stock_name, q)
    return stk_var

$\Delta$CoVaR Calculation¶

Quantile Regression¶

In [43]:
def qr_covar(stock_name, q, qr_var_method, qr_var_modified = True,
             state_variables_series = stateVariables_W,
             market_losses_series = market_losses_W_pct):

    stk_var = var(stock_name, q, qr_var_method, qr_var_modified)
    mkt = market_losses_series.copy()
    svs_lagged = state_variables_series.copy().shift(1).dropna()

    common = svs_lagged.index.intersection(stk_var.index)
    mkt = mkt.loc[common,:]
    reg = svs_lagged.loc[common,:]
    reg[stk_var.name] = stk_var.loc[common]

    qr_model = qr(mkt, sma.add_constant(reg)).fit(q)
    qr_covar_values = qr_model.fittedvalues.rename(stock_name + "_CoVaR_" + str(q))

    return qr_covar_values, qr_model, stk_var
In [44]:
def qr_delta_covar(stock_name, q, qr_var_method, qr_var_modified = True,
                   formula_alter = True):

    if q <= 0.5 and q >= 1:
        raise Exception("Input Error! q should be in (0.5, 1)!")

    if formula_alter:
        _, qr_model_q, stk_var = qr_covar(stock_name, q, qr_var)
        var_median = qr_covar(stock_name, 0.5, qr_var)[2]
        return ((stk_var - var_median) * qr_model_q.params[-1]).rename(stock_name + "_\u0394CoVaR_" + str(q) + "_formula2"), stk_var
    else:
        covar_qr, _, stk_var = qr_covar(stock_name, q, qr_var)
        temp = covar_qr - qr_covar(stock_name, 0.5, qr_var)[0]
        return temp.rename(stock_name + "_\u0394CoVaR_" + str(q) + "_formula1"), stk_var

MLE (Maximum Likelihood Estimation)¶

In [45]:
def MLE_covar_result(params, stock_name, q, series_i, mkt, svs_lagged):
    mu, sigma, p0, p1_0, p1_1, p1_2, p1_3, p1_4, p1_5, p1_6, p2, p3, p4_0, p4_1, p4_2, p4_3, p4_4, p4_5, p4_6, p5 = params
    p1_v = np.array([p1_0, p1_1, p1_2, p1_3, p1_4, p1_5, p1_6])
    p4_v = np.array([p4_0, p4_1, p4_2, p4_3, p4_4, p4_5, p4_6])

    loc_series = p0 + p1_v.dot(svs_lagged.T) + p2 * Trs(series_i)
    scale_series = p3 + p4_v.dot(svs_lagged.T) + p5 * Trs(series_i)
    err_series = (Trs(mkt) - loc_series) / scale_series
    covar_series = []
    for i in range(err_series.shape[0]):
        covar_series.append(scipy.stats.norm(loc_series[i] + mu * scale_series[i], scale_series[i] * sigma).ppf(q))
    loc_series = pd.Series(loc_series, index = mkt.index, name = "loc")
    scale_series = pd.Series(scale_series, index = mkt.index, name = "scale")
    covar_series = pd.Series(covar_series, index = mkt.index, name = stock_name + "_CoVaR_" + str(q))
    error_series = pd.Series(err_series, index = mkt.index, name = "error_term")
    return covar_series, (mu, sigma), pd.concat([covar_series, error_series, loc_series, scale_series], axis = 1)
In [46]:
def MLE_covar(stock_name, q, qr_var_method, qr_var_modified = True,
              state_variables_series = stateVariables_W,
              market_losses_series = market_losses_W_pct):

    stk_var = var(stock_name, q, qr_var_method, qr_var_modified)
    var_i, mkt, svs_lagged = regularize(stk_var, market_losses_series, state_variables_series)
    params = fit_mle_norm(var_i, mkt, svs_lagged)
    return MLE_covar_result(params, stock_name, q, var_i, mkt, svs_lagged)
In [47]:
def MLE_delta_covar(stock_name, q, qr_var_method, qr_var_modified = True):
    if q <= 0.5 and q >= 1:
        raise Exception("Input Error! q should be in (0.5, 1)!")
    covar_MLE, stk_var = MLE_covar(stock_name, q, qr_var_method, qr_var_modified)[:2]
    temp = covar_MLE - MLE_covar(stock_name, 0.5, qr_var_method, qr_var_modified)[0]
    return temp.rename(stock_name + "_\u0394CoVaR_" + str(q)), stk_var

Empirical Study¶

MLE Algorithm Robustness Testing¶

In [48]:
def var_params_MLE(stock_name, 
              market_losses_series = market_losses_W_pct, 
              stocks_losses_series = stocks_losses_W_pct, 
              state_variables_series = stateVariables_W):
    stk, mkt, svs_lagged = regularize(stocks_losses_series[stock_name], market_losses_series, state_variables_series)
    return fit_mle_norm(stk, mkt, svs_lagged), stk, mkt, svs_lagged
In [49]:
max_values = pd.DataFrame(columns = ["Max_Params", "Test_Params"])
params = pd.DataFrame(columns = list(stocks_losses_W_pct.columns))
for stock_name in list(stocks_losses_W_pct.columns):
    params[stock_name], stk, mkt, svs_lagged = var_params_MLE(stock_name)
    test_params = params[stock_name].copy()
    test_params[:] = [3, 1, 0, 0.3, -2, -0.2, 4, -2, -1, -9, 4, 8, -0.7, 1, 0.1, -2, 1, 2, 7, 3]
    max_values.loc[stock_name, "Max_Params"] = log_likelihood_norm(params[stock_name], stk, mkt, svs_lagged)
    max_values.loc[stock_name, "Test_Params"] = log_likelihood_norm(test_params, stk, mkt, svs_lagged)
In [50]:
params
Out[50]:
MMM AOS ABT ABBV ABMD ACN ATVI ADM ADBE ADP ... WMB WTW WYNN XEL XYL YUM ZBRA ZBH ZION ZTS
0 -0.593409 -0.312086 -0.413222 -0.141634 -0.448963 -0.302434 -0.151775 0.062371 0.220366 -0.250235 ... -0.238580 -0.316262 -0.206955 -0.638256 0.206177 -0.059334 -0.342791 -0.360442 0.209166 -0.752245
1 0.304903 0.348305 0.346725 0.248250 0.311587 0.308979 0.303314 0.303780 0.337508 0.264152 ... 0.347177 0.325032 0.254997 0.212796 0.295467 0.305347 0.333449 0.328461 0.315391 0.260009
2 2.900682 -0.028710 2.378961 -2.720184 1.453672 -0.850722 -0.229370 -2.552167 -3.111008 -0.940264 ... -0.107328 -1.175360 0.048824 -0.180683 -0.900945 0.060527 -0.243206 -0.335869 -2.753388 7.124727
3 0.189153 0.188525 0.258063 0.024341 0.156796 0.118914 0.123243 0.000598 0.136935 0.041975 ... -0.162098 0.234018 0.164274 -0.043330 -0.100433 0.193989 0.042768 0.100873 0.062900 0.005246
4 0.953512 -0.047069 0.028129 0.487649 0.191251 0.407374 0.100183 0.006225 0.195955 0.130066 ... -0.140465 -0.232250 -0.081703 0.252342 0.028188 -0.270096 0.262176 0.098542 0.152388 0.235737
5 0.201684 0.194480 0.203328 0.180928 0.189693 0.208437 0.197625 0.166165 0.180771 0.198141 ... 0.176940 0.193396 0.181672 0.192718 0.260920 0.177184 0.203493 0.203121 0.199417 0.271690
6 0.043302 0.323177 0.588991 -0.043655 -1.422947 0.192092 0.513455 -0.318575 -0.184435 0.327794 ... 1.155302 0.735836 0.134231 0.003060 -0.177554 0.277297 -0.095870 0.502489 0.230006 0.216485
7 0.711959 0.234291 0.963591 0.031950 0.399652 1.083671 0.404721 0.089443 -0.444359 -0.005357 ... 0.252600 0.504174 0.124458 0.004588 -0.470181 0.338761 0.101600 0.325555 0.310023 0.329484
8 0.384342 0.093310 0.556777 -0.055902 0.267303 0.356691 -0.112418 -0.077550 -0.061032 -0.177075 ... -0.117127 0.210439 0.255684 0.686932 -0.189749 0.129206 0.380159 0.276297 0.142917 0.162213
9 1.569032 0.518762 0.270970 0.456367 0.729194 0.682479 -0.167666 -3.527279 -3.409657 0.094243 ... -0.580183 0.825879 0.570677 -0.227252 -4.543779 0.202253 -0.998459 0.071429 -1.718285 0.688400
10 2.753715 0.107971 0.534162 0.163717 -0.704851 0.396334 3.225652 -0.449285 0.668838 -0.098824 ... -0.079963 0.558092 -0.762773 -2.164645 2.011886 1.308700 0.616175 1.616364 1.313551 0.174156
11 5.213459 6.019918 6.114866 4.367412 5.442481 5.328669 8.140916 7.838512 5.136429 6.327876 ... 8.372590 6.114176 5.431660 5.779553 8.180928 6.386957 4.382704 5.620795 5.244928 6.004869
12 0.095628 0.172525 0.284202 0.783390 0.210527 0.704736 0.123888 0.323476 -0.005170 0.138028 ... 0.086540 0.251348 0.140119 0.266448 0.246862 0.216869 0.203853 0.096972 0.214852 0.206168
13 0.911315 1.366515 0.309813 0.335979 -0.990807 0.310607 0.206292 -1.589365 -0.584215 0.759049 ... -0.047486 -0.124508 1.327687 0.250566 -1.521734 -0.063421 0.284564 0.610200 0.220993 0.336490
14 0.203431 0.194250 0.224512 0.282407 0.199117 0.212738 0.210626 0.118650 0.283838 0.241159 ... 0.278805 0.229689 0.209822 0.286500 0.221421 0.201937 0.230225 0.236223 0.299092 0.278186
15 0.954357 0.594206 0.328071 0.435051 0.128434 1.703367 1.133346 -1.111123 -1.208614 0.185070 ... -0.047628 1.544605 -0.189319 0.069276 0.296894 0.088691 0.535190 0.304615 -0.320812 0.200915
16 0.071798 0.194811 -0.904123 1.017898 0.213527 0.425862 0.260742 -1.341487 0.357740 0.730372 ... 0.180972 0.483443 0.290696 0.092373 0.108629 0.255912 0.355929 -0.053439 -0.325867 0.135143
17 0.171477 0.286548 1.373528 -0.093262 0.176910 0.240904 0.333000 0.449816 0.288833 -0.312052 ... 0.107920 0.285392 -0.004091 1.053342 -0.647412 0.377137 0.126733 -0.047722 0.064389 0.212846
18 6.298553 5.584104 9.159393 5.382258 4.870595 2.700370 6.294277 5.010385 5.457088 5.720679 ... 5.487325 5.271616 5.461442 5.353551 5.828038 5.663894 5.177705 7.252333 5.605523 5.320002
19 0.380678 2.786513 3.393228 2.626716 -2.764579 2.729649 0.251198 4.099338 -0.996234 2.966177 ... -0.249661 3.194625 3.408782 -1.698298 -3.130028 0.007019 2.916957 2.587023 -1.723819 -0.006971

20 rows × 493 columns

In [51]:
max_values
False in (max_values["Max_Params"] > max_values["Test_Params"])
Out[51]:
Max_Params Test_Params
MMM 59.824164 -17957.347338
AOS 40.293151 -5589.749471
ABT 46.145184 -13205.302339
ABBV 154.673997 -43363.961696
ABMD 151.899154 -10013782.830008
... ... ...
YUM 23.248764 -648333.43476
ZBRA 48.744118 -7341.665783
ZBH 106.409432 -5367.079748
ZION 69.886101 -80872932.686062
ZTS 138.644758 -924932.803433

493 rows × 2 columns

Out[51]:
False
In [52]:
fig = plt.figure(figsize=(20, 12))
ax1 = fig.add_subplot(1, 1, 1)
threshold = -6000
max_vec = max_values[max_values["Test_Params"] >= threshold].loc[:, "Max_Params"]
test_vec = max_values[max_values["Test_Params"] >= threshold].loc[:, "Test_Params"]
for i in range(max_vec.shape[0]):
    y = np.linspace(test_vec.iloc[i], max_vec.iloc[i], 100)
    ax1.plot([max_vec.index[i]] * 100, y, color = "k", zorder = 1)
ax1.scatter(max_vec.index, max_vec, zorder = 2, label = "NLopt log-likelihood function values")
ax1.scatter(test_vec.index, test_vec, zorder = 2, label = "Test log-likelihood function values")
plt.xticks(fontsize=14, rotation = 90)
plt.yticks(fontsize=18)
plt.ylabel("Log-likelihood Function values", fontsize=18)
plt.legend(bbox_to_anchor=(0,-0.2), loc="lower left", fontsize=20)
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c317b88>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c317a48>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c317508>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c317f08>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c311cc8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c321b48>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c321a48>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c328e88>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c328208>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c32cc08>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c32c848>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c328ec8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c321788>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c311908>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c339f08>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c339c48>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c33fe08>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c33f3c8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c33fec8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c339448>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c332648>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c34bfc8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c34bac8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c350dc8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c3508c8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c350808>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1510a8b1048>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c345208>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1510e951388>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c357348>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c367a08>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c357988>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c296108>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c296d48>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c296b88>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c35c4c8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c35c648>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c307d08>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c3079c8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c307c48>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c30fd08>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c30fb08>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c30ff48>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c316e08>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c316788>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c316f88>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c32af48>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c316a08>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c32a948>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c301a48>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c32aa48>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c316c88>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c329288>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c329188>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c32a788>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c33a848>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c33a208>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c33ab88>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c33d0c8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c33da48>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c294c48>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c294848>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c294e48>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c291e08>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c291608>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c291048>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c2a1e88>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c2a1a48>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c2a1f48>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c2a0ec8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c2a07c8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c2a79c8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c2a7fc8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c2a7b48>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c2a7e88>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c2919c8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c2a7188>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c2b8308>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c2b8948>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511c28bb08>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511bad3c08>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511bad39c8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511bad3e88>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511bad8d08>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511bad8a48>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511bad8308>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511badfdc8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511badf308>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511bae4fc8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511bae4f08>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511bae4b08>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511bad30c8>]
Out[52]:
[<matplotlib.lines.Line2D at 0x1511bae4888>]
Out[52]:
<matplotlib.collections.PathCollection at 0x1511baef1c8>
Out[52]:
<matplotlib.collections.PathCollection at 0x1511bb02188>
Out[52]:
([0,
  1,
  2,
  3,
  4,
  5,
  6,
  7,
  8,
  9,
  10,
  11,
  12,
  13,
  14,
  15,
  16,
  17,
  18,
  19,
  20,
  21,
  22,
  23,
  24,
  25,
  26,
  27,
  28,
  29,
  30,
  31,
  32,
  33,
  34,
  35,
  36,
  37,
  38,
  39,
  40,
  41,
  42,
  43,
  44,
  45,
  46,
  47,
  48,
  49,
  50,
  51,
  52,
  53,
  54,
  55,
  56,
  57,
  58,
  59,
  60,
  61,
  62,
  63,
  64,
  65,
  66,
  67,
  68,
  69,
  70,
  71,
  72,
  73,
  74,
  75,
  76,
  77,
  78,
  79,
  80,
  81,
  82,
  83,
  84,
  85,
  86,
  87,
  88,
  89,
  90,
  91,
  92],
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[52]:
(array([-7000., -6000., -5000., -4000., -3000., -2000., -1000.,     0.,
         1000.]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[52]:
Text(0, 0.5, 'Log-likelihood Function values')
Out[52]:
<matplotlib.legend.Legend at 0x1516738b4c8>

VaR computational methods comparison¶

In [53]:
def var_plot(stock_name, ax, q = 0.99, sector = sector, add_legend = False):
    historical = var(stock_name, q, historical_var)
    formula = var(stock_name, q, formula_var)
    qr_author = var(stock_name, q, qr_var, False)[int(window_size * 0.8):]
    qr_modified = var(stock_name, q, qr_var)[int(window_size * 0.8):]
    plot_min = np.array([historical.min(),formula.min(),qr_author.min(),qr_modified.min()]).min() - 5
    plot_max = np.array([historical.max(),formula.max(),qr_author.max(),qr_modified.max()]).max() + 35
    MLE = var(stock_name, q, MLE_var)[int(window_size * 0.8):]

    plt.title(sector[sector.index == stock_name]["Security"].values[0] + " - From " + sector[sector.index == stock_name]["GICS\xa0Sector"].values[0] + " Sector", fontsize=20)
    plt.ylabel("percent", fontsize=18)
    plt.ylim(plot_min, plot_max)
    plt.xticks(fontsize=16, rotation = 30)
    plt.yticks(fontsize=16)
    if add_legend:
        ax.plot(historical, label=str(int(100 *q)) + '%VaR - Nonparametric method')
        ax.plot(formula, label=str(int(100 *q)) + '%VaR - Semiparametric method')
        ax.plot(qr_author, label=str(int(100 *q)) + '%VaR - Parametric method [Quantile Regression - Author]')
        ax.plot(qr_modified, alpha = 0.8, label=str(int(100 *q)) + '%VaR - Parametric method [Quantile Regression - Modified (Add lagged stock losses series)]')
        ax.plot(MLE, label=str(int(100 *q)) + '%VaR - Parametric method [MLE]')
        plt.legend(bbox_to_anchor=(0,-0.4), loc="lower left", fontsize=20)
    else:
        ax.plot(historical)
        ax.plot(formula)
        ax.plot(qr_author)
        ax.plot(qr_modified, alpha = 0.8)
        ax.plot(MLE)
In [54]:
fig = plt.figure(figsize=(25, 22))
ax1 = fig.add_subplot(2, 3, 1)
var_plot("GS", ax1)
ax2 = fig.add_subplot(2, 3, 2)
var_plot("AAPL", ax2)
ax3 = fig.add_subplot(2, 3, 3)
var_plot("MMM", ax3)
ax4 = fig.add_subplot(2, 3, 4)
var_plot("ARE", ax4, add_legend = True)
ax5 = fig.add_subplot(2, 3, 5)
var_plot("CVS", ax5)
ax6 = fig.add_subplot(2, 3, 6)
var_plot("COP", ax6)

CoVar computational methods comparison¶

In [55]:
def covar_plot(stock_name, ax, q = 0.99, sector = sector, add_legend = False):
    MLE_MLE = MLE_covar(stock_name, q, MLE_var)[0]
    qr_MLE = MLE_covar(stock_name, q, qr_var)[0]
    qr_qr = qr_covar(stock_name, q, qr_var)[0]
    MLE_qr = qr_covar(stock_name, q, MLE_var)[0]
    
    if q == 0.5:
        plot_min = np.array([qr_qr, MLE_qr]).min() - 3
        plot_max = np.array([qr_qr, MLE_qr]).max() + 10
    else:
        plot_min = np.array([qr_qr, MLE_qr]).min()
        plot_max = np.array([qr_qr, MLE_qr]).max() + 70

    plt.title(sector[sector.index == stock_name]["Security"].values[0] + " - From " + sector[sector.index == stock_name]["GICS\xa0Sector"].values[0] + " Sector", fontsize=20)
    plt.ylabel("percent", fontsize=18)
    plt.ylim(plot_min, plot_max)
    plt.xticks(fontsize=16, rotation = 30)
    plt.yticks(fontsize=16)
    if add_legend:
        ax.plot(qr_MLE, label=str(int(100 *q)) + '%CoVaR - MLE - from ' + str(int(100 *q)) + '%VaR Quantile Regression')
        ax.plot(MLE_MLE, label=str(int(100 *q)) + '%CoVaR - MLE - from ' + str(int(100 *q)) + '%VaR MLE')
        ax.plot(qr_qr, label=str(int(100 *q)) + '%CoVaR - Quantile Regression - from ' + str(int(100 *q)) + '%VaR Quantile Regression')
        ax.plot(MLE_qr, label=str(int(100 *q)) + '%CoVaR - Quantile Regression - from ' + str(int(100 *q)) + '%VaR MLE')
        plt.legend(bbox_to_anchor=(0,-0.4), loc="lower left", fontsize=20)
    else:
        ax.plot(qr_MLE)
        ax.plot(MLE_MLE)
        ax.plot(qr_qr)
        ax.plot(MLE_qr)
In [56]:
fig = plt.figure(figsize=(25, 18))
ax1 = fig.add_subplot(2, 3, 1)
covar_plot("GS", ax1)
ax2 = fig.add_subplot(2, 3, 2)
covar_plot("AAPL", ax2)
ax3 = fig.add_subplot(2, 3, 3)
covar_plot("MMM", ax3)
ax4 = fig.add_subplot(2, 3, 4)
covar_plot("ARE", ax4, add_legend = True)
ax5 = fig.add_subplot(2, 3, 5)
covar_plot("CVS", ax5)
ax6 = fig.add_subplot(2, 3, 6)
covar_plot("COP", ax6)
In [57]:
fig = plt.figure(figsize=(25, 18))
ax1 = fig.add_subplot(2, 3, 1)
covar_plot("GS", ax1, q = 0.5)
ax2 = fig.add_subplot(2, 3, 2)
covar_plot("AAPL", ax2, q = 0.5)
ax3 = fig.add_subplot(2, 3, 3)
covar_plot("MMM", ax3, q = 0.5)
ax4 = fig.add_subplot(2, 3, 4)
covar_plot("ARE", ax4, q = 0.5, add_legend = True)
ax5 = fig.add_subplot(2, 3, 5)
covar_plot("CVS", ax5, q = 0.5)
ax6 = fig.add_subplot(2, 3, 6)
covar_plot("COP", ax6, q = 0.5)

$\Delta$CoVaR computational methods comparison¶

In [58]:
def delta_covar_plot(stock_name, ax, q = 0.99, sector = sector, add_legend = False):
    MLE_MLE = MLE_delta_covar(stock_name, q, MLE_var)[0]
    qr_MLE = MLE_delta_covar(stock_name, q, qr_var)[0]
    qr_qr_1 = qr_delta_covar(stock_name, q, qr_var, formula_alter = False)[0]
    qr_qr_2 = qr_delta_covar(stock_name, q, qr_var)[0]

    if stock_name in ["GS", "ARE"]:
        plot_min = np.array([qr_qr_1]).min() - 15
        plot_max = np.array([qr_qr_1]).max() + 40
    elif stock_name == "AAPL":
        plot_min = np.array([qr_qr_2]).min() + 100
        plot_max = np.array([MLE_MLE]).max() - 50
    elif stock_name == "MMM":
        plot_min = np.array([qr_qr_2]).min()
        plot_max = np.array([qr_qr_1]).max() + 30
    elif stock_name == "COP":
        plot_min = np.array([qr_qr_2]).min()
        plot_max = np.array([qr_qr_1]).max() + 10
    else:
        plot_min = np.array([qr_qr_2]).min()
        plot_max = np.array([qr_qr_1]).max() + 60

    plt.title(sector[sector.index == stock_name]["Security"].values[0] + " - From " + sector[sector.index == stock_name]["GICS\xa0Sector"].values[0] + " Sector", fontsize=20)
    plt.ylabel("percent", fontsize=18)
    plt.ylim(plot_min, plot_max)
    plt.xticks(fontsize=16, rotation = 30)
    plt.yticks(fontsize=16)
    if add_legend:
        ax.plot(qr_qr_1, label=str(int(100 *q)) + '%\u0394CoVaR - Quantile Regression - Formula1 - from 99%VaR Quantile Regression')
        ax.plot(qr_qr_2, label=str(int(100 *q)) + '%\u0394CoVaR - Quantile Regression - Formula2 - from 99%VaR Quantile Regression')
        ax.plot(qr_MLE, label=str(int(100 *q)) + '%\u0394CoVaR - MLE - from 99%VaR Quantile Regression')
        ax.plot(MLE_MLE, label=str(int(100 *q)) + '%\u0394CoVaR - MLE - from 99%VaR MLE')
        plt.legend(bbox_to_anchor=(0,-0.4), loc="lower left", fontsize=20)
    else:
        ax.plot(qr_qr_1)
        ax.plot(qr_qr_2)
        ax.plot(qr_MLE)
        ax.plot(MLE_MLE)
In [59]:
fig = plt.figure(figsize=(25, 22))
ax1 = fig.add_subplot(2, 3, 1)
delta_covar_plot("GS", ax1)
ax2 = fig.add_subplot(2, 3, 2)
delta_covar_plot("AAPL", ax2)
ax3 = fig.add_subplot(2, 3, 3)
delta_covar_plot("MMM", ax3)
ax4 = fig.add_subplot(2, 3, 4)
delta_covar_plot("ARE", ax4, add_legend = True)
ax5 = fig.add_subplot(2, 3, 5)
delta_covar_plot("CVS", ax5)
ax6 = fig.add_subplot(2, 3, 6)
delta_covar_plot("COP", ax6)

$\Delta$CoVaR and VaR Results¶

In [60]:
def results_plot(stock_name, ax, q = 0.99, sector = sector, add_legend = False, market_losses_series = market_losses_W_pct):
    qr_modified = var(stock_name, q, qr_var)
    qr_qr = qr_delta_covar(stock_name, q, qr_var, formula_alter = False)[0]
    mkt = market_losses_series
    var_series = qr_modified
    delta_covar_series = qr_qr

    plt.title(sector[sector.index == stock_name]["Security"].values[0] + " - From " + sector[sector.index == stock_name]["GICS\xa0Sector"].values[0] + " Sector", fontsize=20)
    plt.ylabel("percent", fontsize=18)
    plt.xticks(fontsize=16, rotation = 30)
    plt.yticks(fontsize=16)
    if add_legend:
        ax.plot(mkt, label='Market Equity Loss')
        ax.plot(var_series, label=str(int(100 *q)) + '%\u0394CoVaR - Quantile Regression - Formula1 - from 99%VaR Quantile Regression')
        ax.plot(delta_covar_series, label=str(int(100 *q)) + '%VaR - Quantile Regression - Modified (Add lagged stock losses series)')
        plt.legend(bbox_to_anchor=(0,-0.4), loc="lower left", fontsize=20)
    else:
        ax.plot(mkt)
        ax.plot(var_series)
        ax.plot(delta_covar_series)
In [61]:
fig = plt.figure(figsize=(25, 17))
ax1 = fig.add_subplot(2, 3, 1)
results_plot("GS", ax1)
ax2 = fig.add_subplot(2, 3, 2)
results_plot("AAPL", ax2)
ax3 = fig.add_subplot(2, 3, 3)
results_plot("MMM", ax3)
ax4 = fig.add_subplot(2, 3, 4)
results_plot("ARE", ax4, add_legend = True)
ax5 = fig.add_subplot(2, 3, 5)
results_plot("CVS", ax5)
ax6 = fig.add_subplot(2, 3, 6)
results_plot("COP", ax6)
In [62]:
var_series_vec = pd.DataFrame(columns = list(stocks_losses_W_pct.columns))
delta_covar_series_vec = pd.DataFrame(columns = list(stocks_losses_W_pct.columns))
for stock_name in list(stocks_losses_W_pct.columns):
    delta_covar_series_vec[stock_name], var_series_vec[stock_name] = qr_delta_covar(stock_name, 0.99, qr_var, formula_alter = False)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
C:\Users\Haochen Jiang\AppData\Roaming\Python\Python37\site-packages\statsmodels\regression\quantile_regression.py:192: IterationLimitWarning: Maximum number of iterations (1000) reached.
  ") reached.", IterationLimitWarning)
In [63]:
var_series_vec_corr = var_series_vec.copy()
delta_covar_series_vec_corr = delta_covar_series_vec.copy()
var_series_vec_corr["Market"] = market_losses_W_pct
delta_covar_series_vec_corr["Market"] = market_losses_W_pct
In [64]:
def print_model_summary(stock_name):
    print(qr_var(stock_name, 0.99)[1].summary())
    print(qr_covar(stock_name, 0.99, qr_var)[1].summary())
In [65]:
output_list = ["GS", "AAPL", "MMM", "ARE", "CVS", "COP"]
for stock_name in output_list:
    print_model_summary(stock_name)
                         QuantReg Regression Results                          
==============================================================================
Dep. Variable:                     GS   Pseudo R-squared:               0.3845
Model:                       QuantReg   Bandwidth:                       2.374
Method:                 Least Squares   Sparsity:                        107.9
Date:                Fri, 20 May 2022   No. Observations:                  991
Time:                        17:42:21   Df Residuals:                      982
                                        Df Model:                            8
========================================================================================
                           coef    std err          t      P>|t|      [0.025      0.975]
----------------------------------------------------------------------------------------
const                    5.0480      0.634      7.966      0.000       3.804       6.291
3MO_Yield_Change        -0.2192      0.068     -3.236      0.001      -0.352      -0.086
Term_Spread_Change       0.2333      0.328      0.711      0.477      -0.411       0.877
TED_Spread               0.0318      0.021      1.544      0.123      -0.009       0.072
Credit_Spread_Change     0.1241      0.649      0.191      0.848      -1.149       1.397
Market_Return           -0.1551      0.422     -0.368      0.713      -0.983       0.673
Excess_Return            0.0871      0.119      0.735      0.462      -0.145       0.320
Equity_Volatility        2.7503      1.175      2.341      0.019       0.445       5.056
stock_lagged            -0.1353      0.160     -0.845      0.399      -0.450       0.179
========================================================================================
                         QuantReg Regression Results                          
==============================================================================
Dep. Variable:          Market_Losses   Pseudo R-squared:               0.3558
Model:                       QuantReg   Bandwidth:                       1.403
Method:                 Least Squares   Sparsity:                        50.78
Date:                Fri, 20 May 2022   No. Observations:                  991
Time:                        17:42:21   Df Residuals:                      982
                                        Df Model:                            8
========================================================================================
                           coef    std err          t      P>|t|      [0.025      0.975]
----------------------------------------------------------------------------------------
const                    5.0712      2.136      2.374      0.018       0.879       9.263
3MO_Yield_Change        -0.1609      0.089     -1.812      0.070      -0.335       0.013
Term_Spread_Change       0.2053      0.144      1.429      0.153      -0.077       0.487
TED_Spread               0.0153      0.015      1.004      0.315      -0.015       0.045
Credit_Spread_Change     0.0248      0.156      0.159      0.874      -0.281       0.331
Market_Return           -0.4239      0.108     -3.911      0.000      -0.637      -0.211
Excess_Return           -0.1022      0.090     -1.138      0.256      -0.279       0.074
Equity_Volatility        4.2378      1.233      3.437      0.001       1.819       6.657
GS_VaR_0.99             -0.4983      0.422     -1.182      0.237      -1.326       0.329
========================================================================================
                         QuantReg Regression Results                          
==============================================================================
Dep. Variable:                   AAPL   Pseudo R-squared:               0.1940
Model:                       QuantReg   Bandwidth:                       2.789
Method:                 Least Squares   Sparsity:                        169.2
Date:                Fri, 20 May 2022   No. Observations:                  991
Time:                        17:42:21   Df Residuals:                      982
                                        Df Model:                            8
========================================================================================
                           coef    std err          t      P>|t|      [0.025      0.975]
----------------------------------------------------------------------------------------
const                    9.2568      1.817      5.094      0.000       5.691      12.823
3MO_Yield_Change        -0.1647      0.092     -1.795      0.073      -0.345       0.015
Term_Spread_Change      -0.1709      0.415     -0.412      0.680      -0.984       0.643
TED_Spread               0.0494      0.030      1.666      0.096      -0.009       0.108
Credit_Spread_Change     0.5221      0.588      0.889      0.374      -0.631       1.675
Market_Return           -0.3802      0.429     -0.887      0.375      -1.221       0.461
Excess_Return           -0.1185      0.107     -1.111      0.267      -0.328       0.091
Equity_Volatility       -0.9962      1.987     -0.501      0.616      -4.896       2.904
stock_lagged            -0.0147      0.219     -0.067      0.947      -0.445       0.416
========================================================================================
                         QuantReg Regression Results                          
==============================================================================
Dep. Variable:          Market_Losses   Pseudo R-squared:               0.3627
Model:                       QuantReg   Bandwidth:                       1.385
Method:                 Least Squares   Sparsity:                        53.43
Date:                Fri, 20 May 2022   No. Observations:                  991
Time:                        17:42:21   Df Residuals:                      982
                                        Df Model:                            8
========================================================================================
                           coef    std err          t      P>|t|      [0.025      0.975]
----------------------------------------------------------------------------------------
const                   59.9508     46.034      1.302      0.193     -30.386     150.287
3MO_Yield_Change        -1.0529      0.828     -1.272      0.204      -2.677       0.571
Term_Spread_Change      -0.9453      0.873     -1.083      0.279      -2.658       0.767
TED_Spread               0.2976      0.253      1.178      0.239      -0.198       0.794
Credit_Spread_Change     3.3478      2.648      1.264      0.207      -1.850       8.545
Market_Return           -2.6027      1.852     -1.406      0.160      -6.236       1.031
Excess_Return           -0.8442      0.612     -1.379      0.168      -2.045       0.357
Equity_Volatility       -3.6388      5.022     -0.725      0.469     -13.494       6.216
AAPL_VaR_0.99           -6.1277      4.986     -1.229      0.219     -15.912       3.657
========================================================================================

The condition number is large, 9.7e+03. This might indicate that there are
strong multicollinearity or other numerical problems.
                         QuantReg Regression Results                          
==============================================================================
Dep. Variable:                    MMM   Pseudo R-squared:               0.1480
Model:                       QuantReg   Bandwidth:                       1.639
Method:                 Least Squares   Sparsity:                        119.9
Date:                Fri, 20 May 2022   No. Observations:                  991
Time:                        17:42:21   Df Residuals:                      982
                                        Df Model:                            8
========================================================================================
                           coef    std err          t      P>|t|      [0.025      0.975]
----------------------------------------------------------------------------------------
const                    5.1777      0.673      7.691      0.000       3.857       6.499
3MO_Yield_Change         0.0280      0.182      0.154      0.878      -0.329       0.385
Term_Spread_Change      -0.0961      0.251     -0.383      0.702      -0.589       0.397
TED_Spread               0.0085      0.025      0.340      0.734      -0.041       0.058
Credit_Spread_Change    -0.0522      0.301     -0.173      0.862      -0.643       0.539
Market_Return           -0.3612      0.245     -1.476      0.140      -0.841       0.119
Excess_Return           -0.0138      0.138     -0.100      0.920      -0.284       0.257
Equity_Volatility        1.8123      0.713      2.540      0.011       0.412       3.212
stock_lagged            -0.0864      0.160     -0.539      0.590      -0.401       0.228
========================================================================================
                         QuantReg Regression Results                          
==============================================================================
Dep. Variable:          Market_Losses   Pseudo R-squared:               0.3557
Model:                       QuantReg   Bandwidth:                       1.415
Method:                 Least Squares   Sparsity:                        56.70
Date:                Fri, 20 May 2022   No. Observations:                  991
Time:                        17:42:21   Df Residuals:                      982
                                        Df Model:                            8
========================================================================================
                           coef    std err          t      P>|t|      [0.025      0.975]
----------------------------------------------------------------------------------------
const                    0.1764      6.881      0.026      0.980     -13.326      13.679
3MO_Yield_Change        -0.0671      0.051     -1.313      0.189      -0.167       0.033
Term_Spread_Change       0.1554      0.149      1.042      0.298      -0.137       0.448
TED_Spread              -0.0051      0.015     -0.345      0.730      -0.034       0.024
Credit_Spread_Change     0.0167      0.172      0.098      0.922      -0.320       0.354
Market_Return           -0.2576      0.437     -0.589      0.556      -1.116       0.600
Excess_Return           -0.1090      0.062     -1.770      0.077      -0.230       0.012
Equity_Volatility        2.0576      2.451      0.839      0.401      -2.753       6.868
MMM_VaR_0.99             0.4666      1.331      0.350      0.726      -2.146       3.079
========================================================================================

The condition number is large, 1.82e+03. This might indicate that there are
strong multicollinearity or other numerical problems.
                         QuantReg Regression Results                          
==============================================================================
Dep. Variable:                    ARE   Pseudo R-squared:               0.4125
Model:                       QuantReg   Bandwidth:                       2.629
Method:                 Least Squares   Sparsity:                        102.6
Date:                Fri, 20 May 2022   No. Observations:                  991
Time:                        17:42:21   Df Residuals:                      982
                                        Df Model:                            8
========================================================================================
                           coef    std err          t      P>|t|      [0.025      0.975]
----------------------------------------------------------------------------------------
const                    3.8848      0.883      4.399      0.000       2.152       5.618
3MO_Yield_Change         0.0108      0.050      0.215      0.830      -0.087       0.109
Term_Spread_Change       0.5247      0.203      2.587      0.010       0.127       0.923
TED_Spread              -0.0167      0.008     -2.105      0.036      -0.032      -0.001
Credit_Spread_Change    -0.2922      0.370     -0.789      0.430      -1.019       0.434
Market_Return           -0.7840      0.283     -2.768      0.006      -1.340      -0.228
Excess_Return           -0.1949      0.269     -0.724      0.469      -0.723       0.333
Equity_Volatility        6.3685      0.944      6.746      0.000       4.516       8.221
stock_lagged            -0.3145      0.235     -1.341      0.180      -0.775       0.146
========================================================================================
                         QuantReg Regression Results                          
==============================================================================
Dep. Variable:          Market_Losses   Pseudo R-squared:               0.3689
Model:                       QuantReg   Bandwidth:                       1.401
Method:                 Least Squares   Sparsity:                        51.46
Date:                Fri, 20 May 2022   No. Observations:                  991
Time:                        17:42:21   Df Residuals:                      982
                                        Df Model:                            8
========================================================================================
                           coef    std err          t      P>|t|      [0.025      0.975]
----------------------------------------------------------------------------------------
const                    4.1222      1.918      2.149      0.032       0.358       7.886
3MO_Yield_Change        -0.0458      0.030     -1.531      0.126      -0.105       0.013
Term_Spread_Change       0.2858      0.328      0.872      0.383      -0.357       0.929
TED_Spread              -0.0084      0.012     -0.677      0.498      -0.033       0.016
Credit_Spread_Change    -0.0687      0.165     -0.418      0.676      -0.392       0.254
Market_Return           -0.6066      0.207     -2.930      0.003      -1.013      -0.200
Excess_Return           -0.1383      0.083     -1.664      0.096      -0.301       0.025
Equity_Volatility        5.2605      2.942      1.788      0.074      -0.513      11.034
ARE_VaR_0.99            -0.3835      0.473     -0.810      0.418      -1.312       0.545
========================================================================================
                         QuantReg Regression Results                          
==============================================================================
Dep. Variable:                    CVS   Pseudo R-squared:              0.08584
Model:                       QuantReg   Bandwidth:                       2.185
Method:                 Least Squares   Sparsity:                        116.1
Date:                Fri, 20 May 2022   No. Observations:                  991
Time:                        17:42:21   Df Residuals:                      982
                                        Df Model:                            8
========================================================================================
                           coef    std err          t      P>|t|      [0.025      0.975]
----------------------------------------------------------------------------------------
const                    7.3797      0.781      9.454      0.000       5.848       8.912
3MO_Yield_Change         0.1346      0.161      0.835      0.404      -0.182       0.451
Term_Spread_Change      -0.6955      0.195     -3.564      0.000      -1.078      -0.313
TED_Spread               0.0457      0.012      3.671      0.000       0.021       0.070
Credit_Spread_Change    -0.1717      0.249     -0.689      0.491      -0.660       0.317
Market_Return           -0.2800      0.243     -1.152      0.250      -0.757       0.197
Excess_Return            0.3629      0.102      3.555      0.000       0.163       0.563
Equity_Volatility       -0.4699      0.674     -0.697      0.486      -1.792       0.852
stock_lagged            -0.1939      0.230     -0.843      0.400      -0.646       0.258
========================================================================================
                         QuantReg Regression Results                          
==============================================================================
Dep. Variable:          Market_Losses   Pseudo R-squared:               0.3545
Model:                       QuantReg   Bandwidth:                       1.398
Method:                 Least Squares   Sparsity:                        61.17
Date:                Fri, 20 May 2022   No. Observations:                  991
Time:                        17:42:21   Df Residuals:                      982
                                        Df Model:                            8
========================================================================================
                           coef    std err          t      P>|t|      [0.025      0.975]
----------------------------------------------------------------------------------------
const                    1.9818      2.385      0.831      0.406      -2.699       6.663
3MO_Yield_Change        -0.0786      0.055     -1.422      0.155      -0.187       0.030
Term_Spread_Change       0.1832      0.280      0.655      0.513      -0.366       0.732
TED_Spread              -0.0045      0.017     -0.267      0.790      -0.038       0.029
Credit_Spread_Change    -0.0244      0.189     -0.129      0.897      -0.396       0.347
Market_Return           -0.3747      0.147     -2.557      0.011      -0.662      -0.087
Excess_Return           -0.1514      0.135     -1.118      0.264      -0.417       0.114
Equity_Volatility        2.7957      0.326      8.583      0.000       2.156       3.435
CVS_VaR_0.99             0.1032      0.325      0.317      0.751      -0.536       0.742
========================================================================================
                         QuantReg Regression Results                          
==============================================================================
Dep. Variable:                    COP   Pseudo R-squared:               0.2890
Model:                       QuantReg   Bandwidth:                       2.370
Method:                 Least Squares   Sparsity:                        125.6
Date:                Fri, 20 May 2022   No. Observations:                  991
Time:                        17:42:21   Df Residuals:                      982
                                        Df Model:                            8
========================================================================================
                           coef    std err          t      P>|t|      [0.025      0.975]
----------------------------------------------------------------------------------------
const                    8.5687      0.690     12.414      0.000       7.214       9.923
3MO_Yield_Change        -0.2165      0.202     -1.070      0.285      -0.614       0.180
Term_Spread_Change      -0.1238      0.285     -0.434      0.664      -0.684       0.436
TED_Spread               0.0037      0.023      0.165      0.869      -0.041       0.048
Credit_Spread_Change     0.7432      0.262      2.841      0.005       0.230       1.257
Market_Return           -0.0830      0.302     -0.275      0.783      -0.675       0.509
Excess_Return           -0.0296      0.127     -0.234      0.815      -0.278       0.219
Equity_Volatility        1.2098      0.681      1.776      0.076      -0.127       2.547
stock_lagged            -0.1853      0.137     -1.348      0.178      -0.455       0.084
========================================================================================
                         QuantReg Regression Results                          
==============================================================================
Dep. Variable:          Market_Losses   Pseudo R-squared:               0.3556
Model:                       QuantReg   Bandwidth:                       1.450
Method:                 Least Squares   Sparsity:                        60.93
Date:                Fri, 20 May 2022   No. Observations:                  991
Time:                        17:42:21   Df Residuals:                      982
                                        Df Model:                            8
========================================================================================
                           coef    std err          t      P>|t|      [0.025      0.975]
----------------------------------------------------------------------------------------
const                    1.8341      3.788      0.484      0.628      -5.598       9.267
3MO_Yield_Change        -0.0329      0.103     -0.321      0.748      -0.234       0.168
Term_Spread_Change       0.0765      0.128      0.596      0.552      -0.176       0.329
TED_Spread              -0.0032      0.012     -0.275      0.783      -0.026       0.020
Credit_Spread_Change    -0.0311      0.389     -0.080      0.936      -0.795       0.733
Market_Return           -0.4099      0.140     -2.927      0.004      -0.685      -0.135
Excess_Return           -0.0770      0.064     -1.202      0.230      -0.203       0.049
Equity_Volatility        2.8947      0.568      5.093      0.000       1.779       4.010
COP_VaR_0.99             0.0893      0.442      0.202      0.840      -0.778       0.957
========================================================================================

Sectors Analysis¶

In [66]:
sector_analyze1 = pd.DataFrame(index = ["\u0394CoVaR", "VaR", "Sector"], columns = list(delta_covar_series_vec.columns))
sector_analyze1.loc["VaR",:] = var_series_vec.iloc[-1,:]
sector_analyze1.loc["\u0394CoVaR",:] = delta_covar_series_vec.iloc[-1,:]
for stock_name in list(sector_analyze1.columns):
    sector_analyze1.loc["Sector", stock_name] = sector.loc[stock_name, "GICS\xa0Sector"]
In [67]:
sector_analyze2 = pd.DataFrame(index = ["\u0394CoVaR", "VaR", "Sector"], columns = list(delta_covar_series_vec.columns))
sector_analyze2.loc["VaR",:] = var_series_vec.iloc[-200,:]
sector_analyze2.loc["\u0394CoVaR",:] = delta_covar_series_vec.iloc[-200,:]
for stock_name in list(sector_analyze2.columns):
    sector_analyze2.loc["Sector", stock_name] = sector.loc[stock_name, "GICS\xa0Sector"]
In [68]:
sector_analyze3 = pd.DataFrame(index = ["\u0394CoVaR", "VaR", "Sector"], columns = list(delta_covar_series_vec.columns))
sector_analyze3.loc["VaR",:] = var_series_vec.iloc[-400,:]
sector_analyze3.loc["\u0394CoVaR",:] = delta_covar_series_vec.iloc[-400,:]
for stock_name in list(sector_analyze3.columns):
    sector_analyze3.loc["Sector", stock_name] = sector.loc[stock_name, "GICS\xa0Sector"]
In [69]:
sector_analyze4 = pd.DataFrame(index = ["\u0394CoVaR", "VaR", "Sector"], columns = list(delta_covar_series_vec.columns))
sector_analyze4.loc["VaR",:] = var_series_vec.iloc[-600,:]
sector_analyze4.loc["\u0394CoVaR",:] = delta_covar_series_vec.iloc[-600,:]
for stock_name in list(sector_analyze4.columns):
    sector_analyze4.loc["Sector", stock_name] = sector.loc[stock_name, "GICS\xa0Sector"]
In [70]:
sector_names = list(set(sector.loc[:, "GICS\xa0Sector"]))
In [71]:
def scatter(stock_name, ax, sector_analyze):
    ax.scatter(sector_analyze.loc["VaR", stock_name], sector_analyze.loc["\u0394CoVaR", stock_name])
In [72]:
fig = plt.figure(figsize=(25, 15))
ax1 = fig.add_subplot(2, 2, 1)
for i, stock_name in enumerate(list(delta_covar_series_vec.columns)):
    scatter(stock_name, ax1, sector_analyze1)
ax1.set_ylabel(str(var_series_vec.iloc[-1,:].name)[:10] + " \u0394CoVaR (percent)", fontsize=18)
ax1.set_xlabel(str(var_series_vec.iloc[-1,:].name)[:10] + " VaR (percent)", fontsize=18)
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)

ax2 = fig.add_subplot(2, 2, 2)
for i, stock_name in enumerate(list(delta_covar_series_vec.columns)):
    scatter(stock_name, ax2, sector_analyze2)
ax2.set_ylabel(str(var_series_vec.iloc[-200,:].name)[:10] + " \u0394CoVaR (percent)", fontsize=18)
ax2.set_xlabel(str(var_series_vec.iloc[-200,:].name)[:10] + " VaR (percent)", fontsize=18)
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)

ax3 = fig.add_subplot(2, 2, 3)
for i, stock_name in enumerate(list(delta_covar_series_vec.columns)):
    scatter(stock_name, ax3, sector_analyze3)
ax3.set_ylabel(str(var_series_vec.iloc[-400,:].name)[:10] + " \u0394CoVaR (percent)", fontsize=18)
ax3.set_xlabel(str(var_series_vec.iloc[-400,:].name)[:10] + " VaR (percent)", fontsize=18)
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)

ax4 = fig.add_subplot(2, 2, 4)
for i, stock_name in enumerate(list(delta_covar_series_vec.columns)):
    scatter(stock_name, ax4, sector_analyze4)
ax4.set_ylabel(str(var_series_vec.iloc[-600,:].name)[:10] + " \u0394CoVaR (percent)", fontsize=18)
ax4.set_xlabel(str(var_series_vec.iloc[-600,:].name)[:10] + " VaR (percent)", fontsize=18)
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)
Out[72]:
Text(0, 0.5, '2022-01-02 ΔCoVaR (percent)')
Out[72]:
Text(0.5, 0, '2022-01-02 VaR (percent)')
Out[72]:
(array([ 0.,  5., 10., 15., 20., 25., 30., 35.]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[72]:
(array([ 2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10.]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[72]:
Text(0, 0.5, '2018-03-11 ΔCoVaR (percent)')
Out[72]:
Text(0.5, 0, '2018-03-11 VaR (percent)')
Out[72]:
(array([ 0.,  5., 10., 15., 20., 25., 30., 35.]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[72]:
(array([ 6.,  7.,  8.,  9., 10., 11., 12.]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[72]:
Text(0, 0.5, '2014-05-11 ΔCoVaR (percent)')
Out[72]:
Text(0.5, 0, '2014-05-11 VaR (percent)')
Out[72]:
(array([ 2.5,  5. ,  7.5, 10. , 12.5, 15. , 17.5, 20. , 22.5, 25. ]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[72]:
(array([3.5, 4. , 4.5, 5. , 5.5, 6. , 6.5, 7. ]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[72]:
Text(0, 0.5, '2010-07-11 ΔCoVaR (percent)')
Out[72]:
Text(0.5, 0, '2010-07-11 VaR (percent)')
Out[72]:
(array([ 0.,  5., 10., 15., 20., 25., 30., 35., 40.]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[72]:
(array([ 8. ,  8.5,  9. ,  9.5, 10. , 10.5, 11. , 11.5, 12. , 12.5]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
In [73]:
diver_names = ["BAC", "C", "CMA", "JPM", "USB", "WFC"]
inves_names = ["SCHW", "GS", "MS"]
insur_names = ["AFL", "GL", "MET", "PFG", "PRU"]
consu_names = ["AXP", "COF", "DFS"]
names_list = [diver_names, inves_names, insur_names, consu_names]
color_list = ["b", "r", "k", "g"]
marker_list = ["o", "^", "v", "+"]
x_adjust_list_1 = list(np.array([-0.09,0.02,0.02,-0.15]) / 3.5)
y_adjust_list_1 = list(np.array([0.05,0.02,-0.1,-0.1]) / 3.5)
x_adjust_list_2 = list(np.array([-0.09,0.02,0.02,-0.15]) / 3)
y_adjust_list_2 = list(np.array([0.05,0.02,-0.1,-0.1]) / 3)
x_adjust_list_3 = list(np.array([-0.09,0.02,0.02,-0.15]) / 3)
y_adjust_list_3 = list(np.array([0.05,0.02,-0.1,-0.1]) / 3)
x_adjust_list_4 = list(np.array([-0.09,0.02,0.02,-0.15]) / 1.75)
y_adjust_list_4 = list(np.array([0.05,0.02,-0.1,-0.1]) / 1.75)
label_list = ["Diversified Banks", "Investment Banking & Brokerage", "Life & Health Insurance", "Consumer Finance"]
In [74]:
fig = plt.figure(figsize=(25, 20))
ax1 = fig.add_subplot(2, 2, 1)
for i, stock_name_list in enumerate(names_list):
    for stock_name in stock_name_list:
        ax1.scatter(sector_analyze1.loc["VaR", stock_name], 
                    sector_analyze1.loc["\u0394CoVaR", stock_name], 
                    color = color_list[i], s = 100, 
                    marker = marker_list[i])
        plt.text(sector_analyze1.loc["VaR", stock_name] + x_adjust_list_1[i], 
                 sector_analyze1.loc["\u0394CoVaR", stock_name] + y_adjust_list_1[i],
                 stock_name, fontsize=14)
    ax1.set_ylabel(str(var_series_vec.iloc[-1,:].name)[:10] + " \u0394CoVaR (percent)", fontsize=18)
    ax1.set_xlabel(str(var_series_vec.iloc[-1,:].name)[:10] + " VaR (percent)", fontsize=18)
    plt.xticks(fontsize=18)
    plt.yticks(fontsize=18)

ax2 = fig.add_subplot(2, 2, 2)
for i, stock_name_list in enumerate(names_list):
    for stock_name in stock_name_list:
        ax2.scatter(sector_analyze2.loc["VaR", stock_name], 
                    sector_analyze2.loc["\u0394CoVaR", stock_name], 
                    color = color_list[i], s = 100, 
                    marker = marker_list[i])
        plt.text(sector_analyze2.loc["VaR", stock_name] + x_adjust_list_2[i], 
                 sector_analyze2.loc["\u0394CoVaR", stock_name] + y_adjust_list_2[i],
                 stock_name, fontsize=14)
    ax2.set_ylabel(str(var_series_vec.iloc[-200,:].name)[:10] + " \u0394CoVaR (percent)", fontsize=18)
    ax2.set_xlabel(str(var_series_vec.iloc[-200,:].name)[:10] + " VaR (percent)", fontsize=18)
    plt.xticks(fontsize=18)
    plt.yticks(fontsize=18)

ax3 = fig.add_subplot(2, 2, 3)
for i, stock_name_list in enumerate(names_list):
    for stock_name in stock_name_list:
        ax3.scatter(sector_analyze3.loc["VaR", stock_name], 
                    sector_analyze3.loc["\u0394CoVaR", stock_name], 
                    color = color_list[i], s = 100, 
                    marker = marker_list[i])
        plt.text(sector_analyze3.loc["VaR", stock_name] + x_adjust_list_3[i], 
                 sector_analyze3.loc["\u0394CoVaR", stock_name] + y_adjust_list_3[i],
                 stock_name, fontsize=14)
    ax3.set_ylabel(str(var_series_vec.iloc[-400,:].name)[:10] + " \u0394CoVaR (percent)", fontsize=18)
    ax3.set_xlabel(str(var_series_vec.iloc[-400,:].name)[:10] + " VaR (percent)", fontsize=18)
    plt.xticks(fontsize=18)
    plt.yticks(fontsize=18)
    
ax3.scatter(sector_analyze3.loc["VaR", "BAC"],  sector_analyze3.loc["\u0394CoVaR", "BAC"], 
            color = color_list[0], s = 100, marker = marker_list[0], label = label_list[0])
ax3.scatter(sector_analyze3.loc["VaR", "SCHW"],  sector_analyze3.loc["\u0394CoVaR", "SCHW"], 
            color = color_list[1], s = 100, marker = marker_list[1], label = label_list[1])
ax3.scatter(sector_analyze3.loc["VaR", "AFL"],  sector_analyze3.loc["\u0394CoVaR", "AFL"], 
            color = color_list[2], s = 100, marker = marker_list[2], label = label_list[2])
ax3.scatter(sector_analyze3.loc["VaR", "AXP"],  sector_analyze3.loc["\u0394CoVaR", "AXP"], 
            color = color_list[3], s = 100, marker = marker_list[3], label = label_list[3])
plt.legend(bbox_to_anchor=(0,-0.4), loc="lower left", fontsize=20)

ax4 = fig.add_subplot(2, 2, 4)
for i, stock_name_list in enumerate(names_list):
    for stock_name in stock_name_list:
        ax4.scatter(sector_analyze4.loc["VaR", stock_name], 
                    sector_analyze4.loc["\u0394CoVaR", stock_name], 
                    color = color_list[i], s = 100, 
                    marker = marker_list[i])
        plt.text(sector_analyze4.loc["VaR", stock_name] + x_adjust_list_4[i], 
                 sector_analyze4.loc["\u0394CoVaR", stock_name] + y_adjust_list_4[i],
                 stock_name, fontsize=14)
    ax4.set_ylabel(str(var_series_vec.iloc[-600,:].name)[:10] + " \u0394CoVaR (percent)", fontsize=18)
    ax4.set_xlabel(str(var_series_vec.iloc[-600,:].name)[:10] + " VaR (percent)", fontsize=18)
    plt.xticks(fontsize=18)
    plt.yticks(fontsize=18)
Out[74]:
<matplotlib.collections.PathCollection at 0x1512335e208>
Out[74]:
Text(11.025310660712211, 4.82812136839541, 'BAC')
Out[74]:
<matplotlib.collections.PathCollection at 0x151229dd2c8>
Out[74]:
Text(13.421559521066646, 4.979035634702523, 'C')
Out[74]:
<matplotlib.collections.PathCollection at 0x151229d3b48>
Out[74]:
Text(8.940643752705556, 5.257030080622478, 'CMA')
Out[74]:
<matplotlib.collections.PathCollection at 0x1510e930748>
Out[74]:
Text(7.711832384028402, 4.796355613705203, 'JPM')
Out[74]:
<matplotlib.collections.PathCollection at 0x1510e930c08>
Out[74]:
Text(9.737030807870857, 5.113862877769345, 'USB')
Out[74]:
<matplotlib.collections.PathCollection at 0x1510a729a48>
Out[74]:
Text(11.400050661240021, 5.107966453609944, 'WFC')
Out[74]:
Text(0, 0.5, '2022-01-02 ΔCoVaR (percent)')
Out[74]:
Text(0.5, 0, '2022-01-02 VaR (percent)')
Out[74]:
(array([ 7.,  8.,  9., 10., 11., 12., 13., 14.]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
(array([4.7, 4.8, 4.9, 5. , 5.1, 5.2, 5.3]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
<matplotlib.collections.PathCollection at 0x151687ca288>
Out[74]:
Text(12.29585036493219, 4.669911982081618, 'SCHW')
Out[74]:
<matplotlib.collections.PathCollection at 0x1510a7f1e48>
Out[74]:
Text(7.680631459012427, 5.218407387605862, 'GS')
Out[74]:
<matplotlib.collections.PathCollection at 0x151229a2648>
Out[74]:
Text(10.353227573635996, 5.0603515760902145, 'MS')
Out[74]:
Text(0, 0.5, '2022-01-02 ΔCoVaR (percent)')
Out[74]:
Text(0.5, 0, '2022-01-02 VaR (percent)')
Out[74]:
(array([ 7.,  8.,  9., 10., 11., 12., 13., 14.]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
(array([4.6, 4.7, 4.8, 4.9, 5. , 5.1, 5.2, 5.3]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
<matplotlib.collections.PathCollection at 0x151229af788>
Out[74]:
Text(9.060226969265976, 4.939146438018123, 'AFL')
Out[74]:
<matplotlib.collections.PathCollection at 0x151229b3488>
Out[74]:
Text(7.742283475028932, 4.713119199844882, 'GL')
Out[74]:
<matplotlib.collections.PathCollection at 0x151229dfcc8>
Out[74]:
Text(12.19892856228477, 4.610516305173214, 'MET')
Out[74]:
<matplotlib.collections.PathCollection at 0x151232e9088>
Out[74]:
Text(13.511206503170863, 5.039061230666232, 'PFG')
Out[74]:
<matplotlib.collections.PathCollection at 0x151232ed408>
Out[74]:
Text(11.52800768231981, 4.861341582983577, 'PRU')
Out[74]:
Text(0, 0.5, '2022-01-02 ΔCoVaR (percent)')
Out[74]:
Text(0.5, 0, '2022-01-02 VaR (percent)')
Out[74]:
(array([ 7.,  8.,  9., 10., 11., 12., 13., 14.]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
(array([4.6, 4.7, 4.8, 4.9, 5. , 5.1, 5.2, 5.3]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
<matplotlib.collections.PathCollection at 0x151232fa708>
Out[74]:
Text(7.4351002224843175, 4.890064769818193, 'AXP')
Out[74]:
<matplotlib.collections.PathCollection at 0x151233000c8>
Out[74]:
Text(9.432803723849311, 5.155478354768496, 'COF')
Out[74]:
<matplotlib.collections.PathCollection at 0x151229dd308>
Out[74]:
Text(13.581254331112353, 4.751191938496731, 'DFS')
Out[74]:
Text(0, 0.5, '2022-01-02 ΔCoVaR (percent)')
Out[74]:
Text(0.5, 0, '2022-01-02 VaR (percent)')
Out[74]:
(array([ 7.,  8.,  9., 10., 11., 12., 13., 14.]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
(array([4.6, 4.7, 4.8, 4.9, 5. , 5.1, 5.2, 5.3]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
<matplotlib.collections.PathCollection at 0x151229a3708>
Out[74]:
Text(20.131986218229223, 8.760081481155181, 'BAC')
Out[74]:
<matplotlib.collections.PathCollection at 0x1512321c688>
Out[74]:
Text(24.888072636816542, 8.807624149431197, 'C')
Out[74]:
<matplotlib.collections.PathCollection at 0x151232f0bc8>
Out[74]:
Text(14.021013034261369, 8.971395516970029, 'CMA')
Out[74]:
<matplotlib.collections.PathCollection at 0x15123374d08>
Out[74]:
Text(14.32498596770619, 8.740866189561215, 'JPM')
Out[74]:
<matplotlib.collections.PathCollection at 0x151229ac188>
Out[74]:
Text(14.890475231531685, 9.07177488824703, 'USB')
Out[74]:
<matplotlib.collections.PathCollection at 0x1510a802f48>
Out[74]:
Text(18.27572473309401, 9.033305681457957, 'WFC')
Out[74]:
Text(0, 0.5, '2018-03-11 ΔCoVaR (percent)')
Out[74]:
Text(0.5, 0, '2018-03-11 VaR (percent)')
Out[74]:
(array([12., 14., 16., 18., 20., 22., 24., 26.]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
(array([8.7 , 8.75, 8.8 , 8.85, 8.9 , 8.95, 9.  , 9.05, 9.1 ]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
<matplotlib.collections.PathCollection at 0x151229dedc8>
Out[74]:
Text(15.48160856630338, 8.678045168025276, 'SCHW')
Out[74]:
<matplotlib.collections.PathCollection at 0x1510e9b99c8>
Out[74]:
Text(10.616007271784305, 8.855706626165519, 'GS')
Out[74]:
<matplotlib.collections.PathCollection at 0x1512331c348>
Out[74]:
Text(14.161239852798857, 8.783066079421515, 'MS')
Out[74]:
Text(0, 0.5, '2018-03-11 ΔCoVaR (percent)')
Out[74]:
Text(0.5, 0, '2018-03-11 VaR (percent)')
Out[74]:
(array([ 8., 10., 12., 14., 16., 18., 20., 22., 24., 26.]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
(array([8.65, 8.7 , 8.75, 8.8 , 8.85, 8.9 , 8.95, 9.  , 9.05, 9.1 ]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
<matplotlib.collections.PathCollection at 0x15123319d88>
Out[74]:
Text(14.769232386117627, 8.730793300730888, 'AFL')
Out[74]:
<matplotlib.collections.PathCollection at 0x1512213b948>
Out[74]:
Text(12.271475333445125, 8.827537956521093, 'GL')
Out[74]:
<matplotlib.collections.PathCollection at 0x15123330108>
Out[74]:
Text(16.961892892341147, 8.538416183758494, 'MET')
Out[74]:
<matplotlib.collections.PathCollection at 0x1512332ce08>
Out[74]:
Text(15.378391171125116, 9.00163511822203, 'PFG')
Out[74]:
<matplotlib.collections.PathCollection at 0x151233363c8>
Out[74]:
Text(18.58089892894169, 8.701827467890098, 'PRU')
Out[74]:
Text(0, 0.5, '2018-03-11 ΔCoVaR (percent)')
Out[74]:
Text(0.5, 0, '2018-03-11 VaR (percent)')
Out[74]:
(array([ 8., 10., 12., 14., 16., 18., 20., 22., 24., 26.]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
(array([8.5, 8.6, 8.7, 8.8, 8.9, 9. , 9.1]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
<matplotlib.collections.PathCollection at 0x15123317208>
Out[74]:
Text(13.11567308377474, 8.909591330506819, 'AXP')
Out[74]:
<matplotlib.collections.PathCollection at 0x151232e4d88>
Out[74]:
Text(17.248171577661473, 8.722397272138272, 'COF')
Out[74]:
<matplotlib.collections.PathCollection at 0x15123325b88>
Out[74]:
Text(15.5157580763464, 8.125946480216642, 'DFS')
Out[74]:
Text(0, 0.5, '2018-03-11 ΔCoVaR (percent)')
Out[74]:
Text(0.5, 0, '2018-03-11 VaR (percent)')
Out[74]:
(array([ 8., 10., 12., 14., 16., 18., 20., 22., 24., 26.]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
(array([8. , 8.2, 8.4, 8.6, 8.8, 9. , 9.2]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
<matplotlib.collections.PathCollection at 0x15122a89f08>
Out[74]:
Text(7.151432624081403, 5.024060892732647, 'BAC')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122a46e08>
Out[74]:
Text(9.87083118288218, 5.117279370709818, 'C')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122a51148>
Out[74]:
Text(8.241366486998471, 5.065137864084337, 'CMA')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122a57288>
Out[74]:
Text(8.417342977755897, 5.185929645014418, 'JPM')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122a1c708>
Out[74]:
Text(8.365886394576286, 5.145825507868754, 'USB')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122a42e08>
Out[74]:
Text(8.415880669613424, 5.012766179046504, 'WFC')
Out[74]:
Text(0, 0.5, '2014-05-11 ΔCoVaR (percent)')
Out[74]:
Text(0.5, 0, '2014-05-11 VaR (percent)')
Out[74]:
(array([ 7. ,  7.5,  8. ,  8.5,  9. ,  9.5, 10. , 10.5]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
(array([4.975, 5.   , 5.025, 5.05 , 5.075, 5.1  , 5.125, 5.15 , 5.175,
        5.2  ]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
<matplotlib.collections.PathCollection at 0x15123313c88>
Out[74]:
Text(10.374770679266712, 5.235494893025883, 'SCHW')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122a41048>
Out[74]:
Text(8.588579076974119, 5.008204739553072, 'GS')
Out[74]:
<matplotlib.collections.PathCollection at 0x15123336588>
Out[74]:
Text(10.654966370095075, 5.033492875898108, 'MS')
Out[74]:
Text(0, 0.5, '2014-05-11 ΔCoVaR (percent)')
Out[74]:
Text(0.5, 0, '2014-05-11 VaR (percent)')
Out[74]:
(array([ 7. ,  7.5,  8. ,  8.5,  9. ,  9.5, 10. , 10.5, 11. ]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
(array([4.95, 5.  , 5.05, 5.1 , 5.15, 5.2 , 5.25]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
<matplotlib.collections.PathCollection at 0x15122a831c8>
Out[74]:
Text(8.349601510704767, 4.937665045621567, 'AFL')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122a890c8>
Out[74]:
Text(5.690650448403877, 4.76226674910921, 'GL')
Out[74]:
<matplotlib.collections.PathCollection at 0x15123322e88>
Out[74]:
Text(9.181792442419702, 5.04972792424652, 'MET')
Out[74]:
<matplotlib.collections.PathCollection at 0x151232f3fc8>
Out[74]:
Text(8.15063776763811, 4.992270535683047, 'PFG')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122acdf08>
Out[74]:
Text(8.371127114398655, 4.917021164371584, 'PRU')
Out[74]:
Text(0, 0.5, '2014-05-11 ΔCoVaR (percent)')
Out[74]:
Text(0.5, 0, '2014-05-11 VaR (percent)')
Out[74]:
(array([ 5.,  6.,  7.,  8.,  9., 10., 11.]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
(array([4.7, 4.8, 4.9, 5. , 5.1, 5.2, 5.3]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
<matplotlib.collections.PathCollection at 0x15122acd9c8>
Out[74]:
Text(7.233721872969256, 5.009940666644258, 'AXP')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122ade508>
Out[74]:
Text(9.114388167965599, 4.932822345843239, 'COF')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122ae6208>
Out[74]:
Text(10.774711116461464, 5.699000146322769, 'DFS')
Out[74]:
Text(0, 0.5, '2014-05-11 ΔCoVaR (percent)')
Out[74]:
Text(0.5, 0, '2014-05-11 VaR (percent)')
Out[74]:
(array([ 5.,  6.,  7.,  8.,  9., 10., 11., 12.]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
(array([4.6, 4.8, 5. , 5.2, 5.4, 5.6, 5.8]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
<matplotlib.collections.PathCollection at 0x15122a3ea48>
Out[74]:
<matplotlib.collections.PathCollection at 0x15122b07b08>
Out[74]:
<matplotlib.collections.PathCollection at 0x15122b17f88>
Out[74]:
<matplotlib.collections.PathCollection at 0x15122b18848>
Out[74]:
<matplotlib.legend.Legend at 0x151229f6888>
Out[74]:
<matplotlib.collections.PathCollection at 0x15122b80508>
Out[74]:
Text(20.78675312085043, 10.613580885937896, 'BAC')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122aa2588>
Out[74]:
Text(29.016092985467203, 10.618919829764092, 'C')
Out[74]:
<matplotlib.collections.PathCollection at 0x15123336248>
Out[74]:
Text(15.791481015923965, 10.609698982917877, 'CMA')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122aecfc8>
Out[74]:
Text(18.29142080134973, 10.248635633065433, 'JPM')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122b1a688>
Out[74]:
Text(19.041548533227648, 10.720554960260174, 'USB')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122a89748>
Out[74]:
Text(20.43147253026597, 10.673783204286163, 'WFC')
Out[74]:
Text(0, 0.5, '2010-07-11 ΔCoVaR (percent)')
Out[74]:
Text(0.5, 0, '2010-07-11 VaR (percent)')
Out[74]:
(array([14., 16., 18., 20., 22., 24., 26., 28., 30.]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
(array([10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
<matplotlib.collections.PathCollection at 0x15122b49308>
Out[74]:
Text(14.54128609981466, 9.80415218968195, 'SCHW')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122bfd1c8>
Out[74]:
Text(10.40050649349813, 10.770722295123342, 'GS')
Out[74]:
<matplotlib.collections.PathCollection at 0x1512333adc8>
Out[74]:
Text(12.725378200053102, 10.917827707067199, 'MS')
Out[74]:
Text(0, 0.5, '2010-07-11 ΔCoVaR (percent)')
Out[74]:
Text(0.5, 0, '2010-07-11 VaR (percent)')
Out[74]:
(array([ 7.5, 10. , 12.5, 15. , 17.5, 20. , 22.5, 25. , 27.5, 30. , 32.5]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
(array([ 9.6,  9.8, 10. , 10.2, 10.4, 10.6, 10.8, 11. ]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
<matplotlib.collections.PathCollection at 0x15122ac8e88>
Out[74]:
Text(18.68252779301686, 10.41043047019693, 'AFL')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122b5e188>
Out[74]:
Text(14.57564192657578, 10.784625828216019, 'GL')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122b69348>
Out[74]:
Text(17.785514972282595, 10.565045499630836, 'MET')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122bc10c8>
Out[74]:
Text(16.014753039800045, 10.722727118997534, 'PFG')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122bc5348>
Out[74]:
Text(19.372434290538106, 10.53910257540016, 'PRU')
Out[74]:
Text(0, 0.5, '2010-07-11 ΔCoVaR (percent)')
Out[74]:
Text(0.5, 0, '2010-07-11 VaR (percent)')
Out[74]:
(array([ 7.5, 10. , 12.5, 15. , 17.5, 20. , 22.5, 25. , 27.5, 30. , 32.5]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
(array([ 9.6,  9.8, 10. , 10.2, 10.4, 10.6, 10.8, 11. ]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
<matplotlib.collections.PathCollection at 0x15122bd09c8>
Out[74]:
Text(15.646612316575755, 10.655770652771997, 'AXP')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122bd9308>
Out[74]:
Text(19.824680758119793, 10.93338707515407, 'COF')
Out[74]:
<matplotlib.collections.PathCollection at 0x15122bc8fc8>
Out[74]:
Text(11.717591426458574, 9.276150104897201, 'DFS')
Out[74]:
Text(0, 0.5, '2010-07-11 ΔCoVaR (percent)')
Out[74]:
Text(0.5, 0, '2010-07-11 VaR (percent)')
Out[74]:
(array([ 7.5, 10. , 12.5, 15. , 17.5, 20. , 22.5, 25. , 27.5, 30. , 32.5]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
Out[74]:
(array([ 9.25,  9.5 ,  9.75, 10.  , 10.25, 10.5 , 10.75, 11.  , 11.25]),
 [Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, ''),
  Text(0, 0, '')])
In [75]:
def sector_plot(ax, j, sector_analyze, legend = False, sector_names = sector_names, v = var_series_vec):
    color_list = ['blue', 'orange', 'green', 'red', 'purple', 'brown', 'pink', 'gray', 'olive', 'cyan', "black"]
    for i, sector_name in enumerate(sector_names):
        temp = sector_analyze.loc[:, sector_analyze.loc["Sector",:] == sector_name]
        ax.scatter(temp.loc["VaR"], temp.loc["\u0394CoVaR"], color = color_list[i], label = sector_name)
        ax.set_ylabel(str(v.iloc[-j,:].name)[:10] + " \u0394CoVaR (percent)", fontsize=18)
        ax.set_xlabel(str(v.iloc[-j,:].name)[:10] + " VaR (percent)", fontsize=18)
        plt.xticks(fontsize=18)
        plt.yticks(fontsize=18)
        if legend:
            plt.legend(bbox_to_anchor=(0,-0.9), loc="lower left", fontsize=20)
In [76]:
fig = plt.figure(figsize=(25, 18))
ax1 = fig.add_subplot(2, 2, 1)
sector_plot(ax1, 1, sector_analyze1)
ax2 = fig.add_subplot(2, 2, 2)
sector_plot(ax2, 200, sector_analyze2)
ax3 = fig.add_subplot(2, 2, 3)
sector_plot(ax3, 400, sector_analyze3, legend = True)
ax4 = fig.add_subplot(2, 2, 4)
sector_plot(ax4, 600, sector_analyze4)

Appendix¶

formula_alternative Data Resources:\

1 FRED-DTB3 - 3months Fred Treasury bill rate in secondary market¶

https://www.quandl.com/data/FRED/DTB3-3-Month-Treasury-Bill-Secondary-Market-Rate \

2 USTREASURY-LONGTERMRATES - Composite Long term bond yield¶

https://www.quandl.com/data/USTREASURY/LONGTERMRATES-Treasury-Long-Term-Rates \

3 USTREASURY-LONGTERMRATES - 3 months libor rate¶

https://www.quandl.com/data/FRED/LIOR3M-3-month-London-Interbank-Offered-Rate-LIBOR \

4 FRED-DGS3MO - 3 months tbill constant maturity rate¶

https://www.quandl.com/data/FRED/DGS3MO-3-Month-Treasury-Constant-Maturity-Rate \

5 Change in Credit Spread¶

https://research.stlouisfed.org/useraccount/datalists/250349